﻿using MasterMasterMode.Content.NPCs;
using Microsoft.Xna.Framework;
using Terraria;
using Terraria.Audio;
using Terraria.ID;
using Terraria.ModLoader;

namespace MasterMasterMode.Common.GlobalTiles
{
    public class WaterBoltTile : GlobalTile
    {
        public override void KillTile(int i, int j, int type, ref bool fail, ref bool effectOnly, ref bool noItem)
        {
            if (type == 50 && !fail && !effectOnly)
            {
                SpawnWaterBolt(i, j);
            }
        }
        private static void SpawnWaterBolt(int tileX, int tileY)
        {
            Vector2 spawnPosition = new(tileX * 16 + 8, tileY * 16 + 8);
            int npcIndex = NPC.NewNPC(Entity.GetSource_NaturalSpawn(), (int)spawnPosition.X, (int)spawnPosition.Y, ModContent.NPCType<WaterBolt>());
            for (int i = 0; i < 10; i++)
            {
                Dust.NewDust(spawnPosition, 20, 20, DustID.Water, Main.rand.NextFloat(-3f, 3f), Main.rand.NextFloat(-3f, 3f), 0, default, 1.2f);
            }
            SoundEngine.PlaySound(SoundID.Item54, spawnPosition);
            if (Main.netMode == NetmodeID.Server)
            {
                NetMessage.SendData(MessageID.SyncNPC, -1, -1, null, npcIndex);
            }
        }
    }
}
